<template>
	<view class="u-p-20">
		<view class="u-flex u-m-b-20">
			<el-input placeholder="请输入链接或者海报Id" v-model="params.searchText" style="width: 200px;"></el-input>
			<el-button @click="confirmSearchText">查询</el-button>

			<el-button @click="asyncAll(0)">全部同步</el-button>
		</view>


		<el-table :data="dataList3" style="width: 100%;height: 700px;" size="mini" height="600px">
			<el-table-column type="index" width="50">
			</el-table-column>
			<el-table-column prop="thumbs" label="图片" width="180">
				<template slot-scope="scope">
					<el-image style="width: 20px; height: 20px" :src="scope.row.thumbnail"
						:preview-src-list="[scope.row.thumbnail]" />
				</template>
			</el-table-column>

			<el-table-column prop="id" label="id">
			</el-table-column>
			<el-table-column fixed="right" label="操作" width="100">
				<template slot-scope="scope">
					<el-button type="text" size="small" @click="asyncData4(scope.row)">删除并数据</el-button>
					<!-- <el-button v-if="scope.row.status == " @click="deleteThis(scope.row)" type="text" size="small">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>
	</view>
</template>

<script>
	let that
	let Authorization = "65d9e1a3-9d62-4f7a-8a58-f9ba64fcc8a8"
	export default {
		data() {
			return {
				params: {
					searchText: ''
				},
				dataList3: []
			}
		},

		onLoad() {
			that = this
		},

		methods: {
			async confirmSearchText() {
				let result2 = await that.$http.Post("admin/poster/findPoster", this.params, "加载中...")
				that.dataList3 = result2.data
			},

			asyncAll(index = 0) {
				if (index == that.dataList3.length) return that.common.showToast("同步成功")

				let item = that.dataList3[index]
				uni.request({
					url: "https://poster.miaogeban.com/poster/template/" + item.id,
					data: {},
					method: 'GET',
					header: {
						"content-type": "application/json",
						"Authorization": Authorization
					},
					timeout: 6000000000,
					success: (res) => {
						let data = res.data.data
						data.tagId = item.tagId
						that.$http.Post("admin/poster/asyncPosterData3", {
							data: data,
							isDelete: true
						}, "同步中...").then(async res => {
							await that.confirmSearchText()
							await that.asyncAll(index + 1)
						})
					},
				})
			},

			asyncData4(item) {
				uni.request({
					url: "https://poster.miaogeban.com/poster/template/" + item.id,
					data: {},
					method: 'GET',
					header: {
						"content-type": "application/json",
						"Authorization": Authorization
					},
					timeout: 6000000000,
					success: (res) => {
						let data = res.data.data
						data.tagId = item.tagId
						that.$http.Post("admin/poster/asyncPosterData3", {
							data: data,
							isDelete: true
						}, "同步中...").then(res => {
							that.confirmSearchText()
						})
					},
				})
			},
		}
	}
</script>

<style>

</style>